package DFS;

import java.util.Arrays;
import java.util.Scanner;

/**
 * create by Sun
 * 2018/8/21
 */
public class DFS1 {
    private static int[][] arr=new int[1000][1000];
    private static int[] vis=new int[1000];

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while (t--!=0){

            int n=sc.nextInt();
            int m=sc.nextInt();

            for(int i=0;i<m;i++){
                int x=sc.nextInt();
                int y=sc.nextInt();
                arr[x][y]=arr[y][x]=1;
            }

            vis[0]=1;
            dfs(0,n);

        }

    }

    private static void dfs(int i, int n) {
        System.out.print(i+" ");

        for(int j=0;j<n;j++){
            if(arr[i][j]==1&&vis[j]!=1){
                vis[j]=1;
                dfs(j,n);
            }
        }

    }
}
